package com.handpay.nocardpay.baselibrary.config;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

/**
 * Created by sxshi on 2017/8/7.
 */

public class NoCardPayConfig {
    public static String APPSERVER; // 生产
    public static boolean isUseHTTPS = false;//是否是https
    public static boolean isTesting = true;//是否测试环境

    // 协议版本号
    public static String HPVIRSION;
    // 渠道
    public static String CHANNEL;
    public static TestEnv ENV;
    // 版本升级渠道
    public static String CLIENTCHANNEL;
    //用于本地数据加密
    public static String ContantKeyModulus;
    public static final String URL_PATH = "hpayMicroView/";
    //友盟UMENG_APPKEY
    public static final String UMENG_APPKEY = "59b6086b45297d676500083a";
    //合合卡识别
    public static final String KEY_CC_CARD = "a1KJbNKWLd1TKL4hN6D74E76";
    //SecureManager key
    public static final String KEY_SECURE = "f9157944f3a7ca5ef4cac37d780dd4325dd178a724b714e8";
    //是否是无卡登录
    public static boolean isNoCardPay;
    //帮助中心
    public static String USERINFO_URL;
    //注册协议
    public static String REGISTATION;
    public static String ADVERTURL;
    //代还款
    //测试3dekey
    private static final String SMARTPAY_DEBUG_KEY = "098f6bcd4621d373cade4e832627b4f62017121111345734";
    //测试环境
    private static final String SMARTPAY_DEBUG_HOST = "http://10.148.181.129/inside/index";

    private static final String DFPAY_DEBUG_HOST = "http://10.148.181.129/hpayDFPaySupport/";
    public static String SMARTPAY_URL;
    public static String SMARTPAY_3DESKEY;
    public static String ONLINE_MARKET_URL;
    public static String RAINDROPS_URL;
    public static String P12KEY;
    public static boolean PRINT_LOG = true;

    static {
        NativeEngine.NativeObject nativeEngine = NativeEngine.initNativeLib();
        APPSERVER = nativeEngine.getAppServer();
        HPVIRSION = nativeEngine.getHPVersion();
        CHANNEL = nativeEngine.getChannel();
        CLIENTCHANNEL = nativeEngine.getClientChannel();
        SecureManager.sMod = nativeEngine.getModulus();
        SecureManager.sPubExp = nativeEngine.getExponent();
        ContantKeyModulus = nativeEngine.getLocalKeyModulus();
        USERINFO_URL = nativeEngine.getHelperCenterUrl();
        REGISTATION = nativeEngine.getRegistation();
        ADVERTURL = nativeEngine.getAdvertUrl();
        SMARTPAY_URL = nativeEngine.getSmartPayUrl();
        SMARTPAY_3DESKEY = nativeEngine.getSmartPay3DesKey();
        ONLINE_MARKET_URL = nativeEngine.getOnlineMarketUrl();
        RAINDROPS_URL = nativeEngine.getRainDropsUrl();
        P12KEY=nativeEngine.getP12Key();
        ENV = new TestEnv(nativeEngine.getDomain(), 80, HPVIRSION, CHANNEL, false); // PRODUCT
//        ENV = new TestEnv("10.148.181.173", 8080, HPVIRSION, CHANNEL, true); // debug
//        ENV = new TestEnv("10.148.181.172", 8080, HPVIRSION, CHANNEL, true); // debug
//        ENV = new TestEnv("10.148.21.80", 8080, HPVIRSION,  CHANNEL, true); // debug
    }


    public static class TestEnv implements Parcelable {
        // 服务端地址
        public String SERVER;
        // 服务端口号
        public int PORT;
        // 服务版本号
        public String HPV;
        // 是否允许自己设置配置
        public boolean CANSET;
        // 渠道号
        public String CHAN;
        // 标志余额查询，使用银联与否
        public boolean BALANCE_ENQUIRE_UP;
        // 是否打印log
        // 是否需要替换地址
        public boolean REPLACEDOMAIN = false;

        TestEnv(String ser, int port, String hpversion, String channel, boolean canSet) {
            SERVER = ser;
            PORT = port;
            HPV = hpversion;
            CHAN = channel;
            BALANCE_ENQUIRE_UP = false;
            CANSET = canSet;
            // 非生产地址，打印log，并设置银联测试地址；生产地址，不打印log，设置银联生产地址
            if (!APPSERVER.contains(ser)) {
                isUseHTTPS = false;
                isTesting = true;
                PRINT_LOG = true;
                SMARTPAY_URL = SMARTPAY_DEBUG_HOST;
                SMARTPAY_3DESKEY = SMARTPAY_DEBUG_KEY;
                RAINDROPS_URL = DFPAY_DEBUG_HOST;
            } else {
                isUseHTTPS = true;
                isTesting = false;
                PRINT_LOG = false;
            }
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(this.SERVER);
            dest.writeInt(this.PORT);
            dest.writeString(this.HPV);
            dest.writeByte(this.CANSET ? (byte) 1 : (byte) 0);
            dest.writeString(this.CHAN);
            dest.writeByte(this.BALANCE_ENQUIRE_UP ? (byte) 1 : (byte) 0);
            dest.writeByte(this.REPLACEDOMAIN ? (byte) 1 : (byte) 0);
        }

        protected TestEnv(Parcel in) {
            this.SERVER = in.readString();
            this.PORT = in.readInt();
            this.HPV = in.readString();
            this.CANSET = in.readByte() != 0;
            this.CHAN = in.readString();
            this.BALANCE_ENQUIRE_UP = in.readByte() != 0;
            this.REPLACEDOMAIN = in.readByte() != 0;
        }

        public static final Parcelable.Creator<TestEnv> CREATOR = new Parcelable.Creator<TestEnv>() {
            @Override
            public TestEnv createFromParcel(Parcel source) {
                return new TestEnv(source);
            }

            @Override
            public TestEnv[] newArray(int size) {
                return new TestEnv[size];
            }
        };

        @Override
        public String toString() {
            return "TestEnv{" +
                    "SERVER='" + SERVER + '\'' +
                    ", PORT=" + PORT +
                    ", HPV='" + HPV + '\'' +
                    ", CANSET=" + CANSET +
                    ", CHAN='" + CHAN + '\'' +
                    ", BALANCE_ENQUIRE_UP=" + BALANCE_ENQUIRE_UP +
                    ", REPLACEDOMAIN=" + REPLACEDOMAIN +
                    '}';
        }
    }
}
